package com.ymm.controller;

import com.ymm.domain.entity.Advice;
import com.ymm.domain.vo.ResponseResult;
import com.ymm.enums.AppHttpCodeEnum;
import com.ymm.service.AdviceService;
import com.ymm.service.ExamService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 椰咩咩咩
 * @version 1.0-SNAPSHOT
 * @date 2023/4/14 17:11
 * @Description 处理医生相关的事务
 */
@RequestMapping("/advice")
@RestController
public class AdviceController {

    @Resource
    private AdviceService adviceService;

    @GetMapping("/exam/list")
    public ResponseResult getExamList(
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(required = false) String name,
            @RequestParam(defaultValue = "0") Integer dataType) {
        return adviceService.getExamList(pageNum, pageSize, name, dataType);
    }

    @PostMapping
    public ResponseResult addAdvice(@RequestBody Advice advice) {
        boolean b = adviceService.save(advice);
        return b ? ResponseResult.okResult() : ResponseResult.errorResult(AppHttpCodeEnum.ADD_FAIL);
    }

    @GetMapping("/list/{id}")
    public ResponseResult getAdviceByExam(@PathVariable Long id) {
        return adviceService.getAdviceByExam(id);
    }

}
